 
package org.dusin.weijiwufang.ui.action;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.awt.print.*;

public class PrintBlankTicket implements Printable, ActionListener {


    public int print(Graphics g, PageFormat pf, int page) throws
                                                        PrinterException {

        if (page > 0) { /* We have only one page, and 'page' is zero-based */
            return NO_SUCH_PAGE;
        }

        /* User (0,0) is typically outside the imageable area, so we must
         * translate by the X and Y values in the PageFormat to avoid clipping
         */
        Graphics2D g2d = (Graphics2D)g;
        g2d.translate(pf.getImageableX(), pf.getImageableY());
        Font font = new Font("宋体",Font.BOLD,20);
        Font oldFont;
        oldFont = g.getFont();
        g.setFont(font);
        /* Now we perform our rendering */
        g.drawString("调度任务操作票", 200, 20);
        g.drawLine(180, 25, 370, 25);
        
        g.drawRect(10, 35, 520, 680);
        g.drawLine(20, 65, 520, 65);
        g.drawLine(20, 90, 520, 90);
        
        g.drawLine(10, 110, 530, 110);
        
        g.drawLine(40, 110, 40, 635);//三列
        g.drawLine(70, 110, 70, 715);
        g.drawLine(420, 110, 420, 635);       
        
        g.setFont(oldFont);
        g.drawString("命令操作时间：", 40, 60);
        g.drawString("操作终了汇报时间：", 250, 60);
        g.drawString("操作任务：", 40, 85);
        g.drawLine(10, 135, 530, 135);
        g.drawString("执行", 10+1, 135-5);
        g.drawString("顺序", 40+1, 135-5);
        g.drawString("操   作   内   容", 70+120, 135-5);
        g.drawString("时  分", 420+40, 135-5);
        
        for(int i=1;i<=25;i++){
            g.drawLine(10, 135+20*i, 530, 135+20*i);            
            g.drawString(""+i, 40+5, 135-5+20*i);
        }
        
        g.drawString("备注", 25, 680);
        g.drawString("发令人：", 35, 730);
        g.drawLine(85, 735, 140, 735);
        g.drawString("值班长:", 150, 730);
        g.drawLine(205, 735, 260, 735);
        g.drawString("监护人:", 265, 730);
        g.drawLine(315, 735, 370, 735);
        g.drawString("操作人:", 380, 730);
        g.drawLine(430, 735, 485, 735);
        
        g.drawString("填票人：", 35, 750);
        g.drawLine(85, 755, 140, 755);
        g.drawString("检查人:", 150, 750);
        g.drawLine(205, 755, 260, 755);
        /* tell the caller that this page is part of the printed document */
        return PAGE_EXISTS;
    }

    public void actionPerformed(ActionEvent e) {
         PrinterJob job = PrinterJob.getPrinterJob();
         job.setPrintable(this);
         boolean ok = job.printDialog();
         if (ok) {
             try {
                  job.print();
             } catch (PrinterException ex) {
              /* The job did not successfully complete */
             }
         }
    }    
}
